package com.tonglin.springboot.controller;

/**
 *
 * 1.接受数据
 * 2.返回页面
 *
 *
 */

import com.tonglin.springboot.po.Status01;
import com.tonglin.springboot.po.Status02;
import com.tonglin.springboot.service.UpdateService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UpdatePasswordController {

    @Autowired
    UpdateService updateService;

    @RequestMapping("update")
    public String update(String userId, String userName, String passWord1, String passWord2, Model model){
        if(StringUtils.isBlank(userId)){

            model.addAttribute("msg02","用户id不能为空！");
            return "update";
        }

        Integer userID = Integer.parseInt(userId);
        Status02 status02 = updateService.updateService(userID,userName,passWord1,passWord2);

        if (status02.isCode()){
            model.addAttribute("mm02",status02);
            model.addAttribute("name",userName);

            return "msg02";
        }
        else {
            model.addAttribute("msg02",status02.getMsg());


            return "update";

        }


    }
}
